
axios.defaults.baseURL = ' http://124.223.14.236:3001/api';
const qs = (ele) => document.querySelector(ele)
// 接口地址：https://www.apifox.cn/apidoc/shared-36f0cbc0-9064-44bc-850a-805e263bf494/api-25827426
async function init() {
    let { data: { data } } = await axios.get('/city/province')
    console.log(data);
    let n = data.map(item => `<option value="${item.province}">${item.name}</option>`).join('')
    qs('#province').innerHTML = '	<option value="">请选择省份</option>' + n
    qs('#province').value = '34'
    // 市
    let { data: { data: res } } = await axios.get('/city/city', {
        params: {
            provinceCode: qs('#province').value
        }
    })
    console.log(res);

    let m = res.map(item => `<option value="${item.city}">${item.name}</option>`).join('')
    qs('#city').innerHTML = '<option value="">请选择城市</option>' + m
    qs('#city').value = '01'
    // 区
   let {data:{data:res1}}= await axios.get('/city/area',{params:{
        provinceCode:qs('#province').value,
        cityCode: qs('#city').value
    }})
    console.log(res1);
    let j = res1.map(item => `<option value="${item.area}">${item.name}</option>`).join('')
    qs('#county').innerHTML = '<option value="">请选择区县</option>' + j
    qs('#county').value = '02'
}
init()

// 
qs('#province').addEventListener('change',async function(){
    // this.value

    let { data: { data: res } } = await axios.get('/city/city', {
        params: {
            provinceCode: this.value
        }
    })
    let m = res.map(item => `<option value="${item.city}">${item.name}</option>`).join('')
    qs('#city').innerHTML = '<option value="">请选择城市</option>' + m
    qs('#county').innerHTML = '<option value="">请选择区县</option>'
})
qs('#city').addEventListener('change',async function(){
    // this.value

    let {data:{data:res1}}= await axios.get('/city/area',{params:{
        provinceCode:qs('#province').value,
        cityCode: qs('#city').value
    }})
    console.log(res1);
    let j = res1.map(item => `<option value="${item.area}">${item.name}</option>`).join('')
    qs('#county').innerHTML = '<option value="">请选择区县</option>' + j
})